﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Common;

namespace JM.JCY.SharePointComponent.Event.EventHome
{
    public partial class EventHomeUserControl : UserControl
    {
        public int _userId
        {
            set { ViewState["_userId"] = value; }
            get { return (int)ViewState["_userId"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (ApplicationContext.Current.GetKeyValue("userId") != null)
            {
                _userId = Int32.Parse(ApplicationContext.Current.GetKeyValue("userId").ToString());
            }
            if (!IsPostBack)
            {
                using (EventProxy proxy = new EventProxy())
                {
                    var dt = proxy.GetEventForHome(Int32.Parse(JCYConstant.DisplayCount), _userId);
                    this.dlEvent.DataSource = dt;
                    this.dlEvent.DataBind();
                }
            }
        }

        protected void dlEvent_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            // load date format
            Label lblEffDate = (Label)e.Item.FindControl("lblEffDate");

            string dateString = lblEffDate.Text;
            DateTime dateTime = DateTime.Parse(dateString);
            lblEffDate.Text = dateTime.ToString(JCYConstant.Date_Format_CN);
        }
    }
}
